home *** CD-ROM | disk | FTP | other *** search
- {
- 4-waves distortion of a 320x200 bitmap
- by Maple Leaf, 1996
- ------------------------------------------------------------------------
- "version" 2 (AT LEAST four times faster than the previous... ASM RULES!)
- no comments. watch the assembler parts if you want to understand something.
-
- Do whatever you want with this code, but if you intend to use any parts of
- it, please credit me - say "hello Maple Leaf" or something, and this should
- be quite enough...
- }
-
- uses alloc, dosio, bitmap;
-
- var vScr, Temp : word;
- Img : pointer;
- Pal : array[byte] of record r,g,b:byte end;
-
- Wave1, Wave2 : array [0..199] of integer; { Left/Right }
- Wave3, Wave4 : array [0..319] of integer; { Up/Down }
-
- SinTab, CosTab : array [byte] of integer; { sine and cosine }
-
- MaxAmplV, MaxAmplH, AngleIncrement : word;
-
- procedure InitVideo;near;assembler;
- asm
- mov ax,13h
- int 10h { init video mode }
- mov dx,3c8h
- mov al,0
- out dx,al
- inc dx
- mov cx,768
- mov si,offset pal
- rep outsb { set palette }
- end;
-
- procedure vWait;near;assembler;
- asm
- mov dx,3DAh
- @1: in al,dx
- test al,8
- jne @1
- @2: in al,dx
- test al,8
- je @2
- end;
-
- procedure ShowVScreen;near;assembler;
- asm
- push ds
- push es
- mov cx,16000
- mov ax,0A000h
- mov es,ax
- mov di,0
- mov si,di
- mov ds,VScr
- cld
- db 66h; rep movsw
- pop es
- pop ds
- end;
-
- procedure freeAll;
- begin
- free(img);
- hfree(vScr);
- hfree(Temp);
- end;
-
- procedure InitData;
- var k:word;
- begin
- vScr:=halloc(64000);
- Temp:=halloc(64000);
- Img:=LoadPCX(paramstr(1),@pal);
- if (Img=nil) or (vScr=0) or (Temp=0) then begin
- freeAll;
- asm mov ax,3; int 10h end;
- writeln('Not enough memory');
- halt
- end;
- for k:=0 to 255 do begin
- SinTab[k]:=trunc(255*sin(k/255*2*pi));
- CosTab[k]:=trunc(255*cos(k/255*2*pi));
- end;
- end;
-
- procedure UpdateWaves;near;external;
- procedure HoriDistort;near;external;
- procedure VertDistort;near;external;
- {$L distasm}
-
- procedure DoIt;
- begin
- MaxAmplH:=10; { amplitude of variation (horizontal) }
- MaxAmplV:=4; { amplitude of variation (vertical) }
- AngleIncrement:=5; { this will be the speed of distorsion ... }
- repeat
- UpdateWaves;
- HoriDistort;
- VertDistort;
- vWait;
- ShowVScreen;
- until port[$60]=1;
- end;
-
- begin
- if paramcount=0 then begin
- writeln('Parameter expected (FileName.PCX)');
- halt
- end;
- InitData;
- InitVideo;
- DoIt;
- asm mov ax,3; int 10h end;
- freeAll;
- end.
-